package com.zhuiYun.project.api.commodityType.controller;

import com.zhuiYun.project.annotation.OptLog;
import com.zhuiYun.project.api.commodity.model.CommodityModel;
import com.zhuiYun.project.api.commodity.service.CommodityService;
import com.zhuiYun.project.api.commodityType.entity.CommodityType;
import com.zhuiYun.project.api.commodityType.model.CommodityTypeModel;
import com.zhuiYun.project.api.commodityType.service.CommodityTypeService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonConstants;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName CommodityTypeController
 * @Description TODO
 * Author 高
 * @Date 2023/4/3 20:31
 * @Version 1.0
 **/
@RestController
@RequestMapping("/CommodityType")
@Api(tags = "日志操作模块")
@Slf4j
public class CommodityTypeController extends BaseController {
    @Autowired
    CommodityTypeService commodityTypeService;
    /**
     * 树全查
     * @param
     * @return
     */
    @GetMapping("/getCommodityTypeList")
    public List<CommodityType> getCarTypeList(){//获取车类型list
        return commodityTypeService.getCommodityTypeList();
    }
    /**
     * 查询商品类型信息
     * @param CommodityTypeModel
     * @return
     */
    @GetMapping("/getCommodityTypeByPage")
    @ApiOperation(value = "类型信息的分页查询方法")
    @OptLog(modular = "商品类型信息管理", type = CommonConstants.SELECT, describe = "分页查询")
    public CommonResult getCommodityTypeByPage(CommodityTypeModel CommodityTypeModel, PageRequest pageRequest) throws CommonException {
        log.info("商品类型信息管理");
        return commodityTypeService.getCommodityTypeByPage(CommodityTypeModel,pageRequest);
    }
    /**
     * 添加类型信息
     * @param
     * @return
     */
    @PostMapping("/publishCommodityTypeAdd")
    @ApiOperation(value = "类型信息的新增方法")
    @OptLog(modular = "新增类型信息", type = CommonConstants.ADD, describe = "类型信息")
    public CommonResult CommodityTypeAdd(MultipartFile[] typeImg, CommodityTypeModel publish) throws CommonException{
        int i = commodityTypeService.CommodityTypeAdd(typeImg, publish);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }
    /**
     * 修改类型信息
     * @param
     * @return
     */
    @PostMapping("/CommodityTypeUpdate")
    @ApiOperation(value = "类型信息修改方法")
    @OptLog(modular = "修改类型信息", type = CommonConstants.UPDATE, describe = "类型信息")
    public CommonResult CommodityTypeUpdate(MultipartFile[] typeImg, CommodityTypeModel publish) throws CommonException{
        int i = commodityTypeService.CommodityTypeUpdate(typeImg, publish);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.error("添加失败");
        }
    }

    /**
     * 逻辑删除
     * @param
     * @return
     */
    @DeleteMapping("/delCommodityTypeById")
    @ApiOperation(value = "逻辑删除类型的方法")
    @OptLog(modular = "逻辑删除类型", type = CommonConstants.DELETE, describe = "逻辑删除类型")
    public CommonResult delCommodityTypeById(Integer id) throws CommonException {
        log.info("逻辑删除类型");
        return commodityTypeService.delCommodityTypeById(id);
    }
    /**
     * 树删除
     * @param
     * @return
     */
    @DeleteMapping("/delCommodityTypeById1")
    @ApiOperation(value = "逻辑删除类型的方法")
    @OptLog(modular = "逻辑删除类型", type = CommonConstants.DELETE, describe = "逻辑删除类型")
    public CommonResult delCommodityType1(Integer id) throws CommonException {
        log.info("逻辑删除类型");
        return commodityTypeService.delCommodityType1(id);
    }


}

